"""
配置文件管理 - 支持多环境切换
"""
import yaml
from pathlib import Path
from typing import Dict, Any


class ConfigManager:
    def __init__(self, environment='test'):
        self.environment = environment
        self.config = self._load_config()

    def _load_config(self) -> Dict[str, Any]:
        """加载配置文件"""
        config_file = f'config/config_{self.environment}.yaml'
        config_path = Path(__file__).parent.parent.parent / config_file

        if not config_path.exists():
            raise FileNotFoundError(f"配置文件不存在: {config_path}")

        with open(config_path, 'r', encoding='utf-8') as f:
            return yaml.safe_load(f)

    def get_website_config(self) -> Dict[str, Any]:
        """获取网站配置"""
        return self.config.get('website', {})

    def get_account_config(self, account_type='default') -> Dict[str, Any]:
        """获取账号配置"""
        accounts = self.config.get('accounts', {})
        return accounts.get(account_type, {})

    def get_api_config(self) -> Dict[str, Any]:
        """获取API配置"""
        return self.config.get('api', {})

    def get_database_config(self) -> Dict[str, Any]:
        """获取数据库配置"""
        return self.config.get('database', {})